The definitions of And and Or are:
#math104#
And~a~b |
= |
#tex2html_wrap_indisplay2226##tex2html_wrap_indisplay2227# |
|
Or~a~b |
= |
#tex2html_wrap_indisplay2231##tex2html_wrap_indisplay2232# |
|
With our definition of what a boolean is, this is just the same as
#math105#
And~a~b |
= |
a~b~False |
|
Or~a~b |
= |
a~True~b |
|
;SPMgt;From these conditions, we can show that And is associative, and
has left unit True and left zeros False and Error:
#math106#
And~(And~a~b)~c |
= |
And~a~(And~b~c) |
|
And~True~b |
= |
b |
|
And~False~b |
= |
False |
|
And~Error~b |
= |
Error |
|
Or is associative, has left unit False and left zeros True and Error:
#math107#
Or~(Or~a~b)~c |
= |
Or~a~(Or~b~c) |
|
Or~False~b |
= |
b |
|
Or~True~b |
= |
True |
|
Or~Error~b |
= |
Error |
|
De~Morgan's laws hold:
#math108#
Not~(And~a~b) |
= |
Or~(Not~a)~(Not~b) |
|
Not~(Or~a~b) |
= |
And~(Not~a)~(Not~b) |
|
and And and Or left-distribute through one another:
#math109#
Or~a~(And~b~c) |
= |
And~(Or~a~b)~(Or~a~c) |
|
And~a~(Or~b~c) |
= |
Or~(And~a~b)~(And~a~c) |
|
And and Or are <#171#>not<#171#> commutative, though. For example,
#math110#
Or~True~Error;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp; |
|
= |
True~True~Error |
|
|
= |
True |
|
but
#math111#
Or~Error~True;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp; |
|
= |
Error~True~True |
|
|
= |
Error |
|
This is actually quite useful since there are some booleans that
need to return an error occasionally. If a is True when b
is safe (i.e. doesn't become Error) and is False otherwise, we can
say Or~a~b and know we're not going to get an error. This is handy
for things like checking for division by zero, or trying to get the
first element of an empty list.
Similarly, because of the possibility of Error,
And and Or don't right-distribute through each other,
as
#math112#
Or~(And~False~Error)~True;SPMnbsp;;SPMnbsp;;SPMnbsp;;SPMnbsp; |
|
≠ |
And~(Or~False~True)~(Or~Error~True) |
|
As errors shouldn't crop up, this needn't worry us too much.